<template>
    <div>
        <h1>病房添加页面</h1>
            <table>
                <thead>
                    <tr>
                        <td>病房号</td>
                        <td><input type="text" v-model="data.bnumber"></td>
                    </tr>
                    <tr>
                        <td>病房名称</td>
                        <td><input type="text" v-model="data.bName"></td>
                    </tr>
                    <tr>
                        <td>科室</td>
                        <td>
                            <select v-model="data.kid" >
                                <option value="0">请选择</option>
                                <option v-for="a in Xiala1" :value="a.kid">{{a.keName}}</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>床位总数量</td>
                        <td><input type="text" v-model="page.inde"></td>
                    </tr>
                    <tr>
                        <td>床位空闲数量</td>
                        <td><input type="text" v-model="page.index"></td>
                    </tr>
                    <tr>
                        <td>创建日期</td>
                        <td><input type="date" v-model="data.times"></td>
                    </tr>
        
                    <tr>
                        <td></td>
                        <td><input type="button" value="添加" @click="Add">
                        <a href="/BingHomeShow">返回</a>
                        </td>
                    </tr>
                </thead>
            </table>
    </div>
</template>

<script setup lang="ts">
import {onMounted, ref} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'
const router = useRouter();
onMounted(()=>{
Xiala();
})

const Xiala1=ref([{
    "kid": 4,
    "keName": "一类科室",
    "kePeople": "15",
    "keMiaoS": "心血疾病专家",
    "keTimes": "2025-05-19T00:00:00",
    "keLuoji": true
}])

const Xiala=()=>{
    axios.get("/api/KeHome/GetKeshiQuan").then(res=>{
        Xiala1.value=res.data;
    })
}

var page = ref({
    inde:'',
    index:''
})

const data = ref({
      "bid": 0,
  "bnumber": "",
  "bName": "",
  "kid": 0,
  "bednum": 0,
  "zid": 0,
  "bedKong": 0,
  "times": "2025-05-19T03:47:23.111Z"
});

const Add=()=>{
    if(data.value.bName=="")
{
    alert("病房名称不能为空!");
    return;
}
if(data.value.bName.length>6)
{
    alert("病房名称不能超过6个字符!");
    return;
}
    data.value.bednum = page.value.inde==''?0:page.value.inde;
    data.value.bedKong = page.value.index==''?0:page.value.index;
    axios.post("/api/BingHome/AddBingHome",data.value).then(res=>{
        if(res.data>0)
    {
        alert("添加成功");
        router.push({path:'/BingHomeShow'});
    }
    else{
         alert("添加失败");
         return;
    }
    })
}

</script>

<style scoped>

</style>